<template>
	<view class="">

		<view style="height:150rpx;"></view>

		<view style="text-align: center;font-weight: bold;font-size: 26px;margin-bottom: 10px;">下面是使用了多语言</view>
		<!-- <view>这里是中文的语言</view> -->

		<!-- <view class="padding im-flex im-rows im-justify-content-center mb-10">
			<view class="im-flex im-rows im-justify-content-center">
				<image class="login-logo " :src="app_logo" mode="fixWidth"></image>
			</view>
		</view> -->

		<view class="im-flex im-rows im-justify-content-center">{{$t('change.例如')}}</view>

		<view class="btn">
			<view class="btn_item">
				<u-button text="切换语言" type="primary" size="large" @click="ChangeCN()"></u-button>
			</view>
			<view class="btn_item">
				<u-button text="تىل ئالماشتۇرۇش" type="error" size="large" @click="ChangeUyghur()"></u-button>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				applicationLocale: "zh-Hans",
				app_logo: uni.getStorageSync('app_logo'),
			};
		},
		onShow() {
			// this.initLangeage()
		},
		methods: {
			ChangeCN() {
				this.$i18n.locale = 'zh-Hans';
				uni.setStorageSync('lang', this.$i18n.locale)
				uni.setLocale(this.$i18n.locale);
				//this.showLang = false
				//
				this.changeTab()
				// uni.reLaunch({
				// 	url: '/pages/index/index'
				// })
			},
			ChangeUyghur() {
				this.$i18n.locale = 'zh-Uyghur';
				uni.setStorageSync('lang', this.$i18n.locale)
				uni.setLocale(this.$i18n.locale);
				//this.showLang = false
				this.changeTab()
				this.font()
				// uni.reLaunch({
				// 	url: '/pages/index/index'
				// })
				this.changeTab()
			},
			font() {
				uni.loadFontFace({
					family: 'CN',
					source: `url('https://jiangxinsaas.oss-cn-beijing.aliyuncs.com/tuchuang/251712277805kLrxi9.ttf')`,
					success() {
						console.log('success')
					},
					fail(res) {
						console.log('fail', res)
					}
				})
			},
			changeTab() {
				
				var that = this
				uni.switchTab({
					url: '/pages/index/index',
					success: function() {
						uni.setTabBarItem({
							index: 0,
							text: that.$t('change.首页')
						})
						uni.setTabBarItem({
							index: 1,
							text: that.$t('change.服务')
						})
						uni.setTabBarItem({
							index: 2,
							text: that.$t('change.消息')
						})
						uni.setTabBarItem({
							index: 3,
							text: that.$t('change.我的')
						})
					}
				});
			},
			switchcn() {
				uni.showModal({
					title: '切换语言',
					content: '切换到中文？',
					confirmText: '确定',
					cancelText: '取消',
					success: res => {
						if (res.confirm) {
							this.$i18n.locale = 'zh-Hans';
							uni.setStorageSync('lang', this.$i18n.locale)
							uni.setLocale(this.$i18n.locale);
						}
					}
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.login-logo {
		width: 180rpx;
		height: 180rpx;
		font-size: 80rpx;
		text-align: center;
		line-height: 120rpx;
		border-radius: 18rpx;
	}

	.btn {
		display: flex;
		bottom: 50px;
		position: fixed;
		width: 100%;
		padding: 15px;
		justify-content: space-between;

		.btn_item {
			width: 45%;
		}
	}
</style>